Skip to content

Validate Base58Check version bytes and SegWit format in btc_address() - #589

Open
ijwino wants to merge 1 commit into
python-validators:masterfrom
ijwino:fix/btc-address-validation
Open

ijwino wants to merge 1 commit into
python-validators:masterfrom
ijwino:fix/btc-address-validation

Conversation

@ijwino

@ijwino ijwino commented Nov 21, 2026

Copy link
Copy Markdown

Fixes two false positives in btc_address():

  • Base58Check addresses were validated by checksum only, accepting valid addresses from other chains (e.g. TRON, Litecoin, Dogecoin). Added a prefix/length regex pre-filter, restricted version bytes to Bitcoin mainnet (0x00, 0x05) and testnet (0x6f, 0xc4) per Bitcoin Wiki: List of address prefixes, and handled 25-byte OverflowError on 35-char inputs.
  • The SegWit regex matched [0-3] instead of the literal '1' separator and didn't enforce BIP-173 / BIP-350 witness version (0-16) or program length bounds (v0: 20/32 bytes, v1-16: 2-40 bytes).

Added regression tests using Bitcoin Core's key_io_valid.json and BIP-173/BIP-350 test vectors.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant